Skip to content

feat: use official Cloudflare TypeScript API Library#783

Closed
andykenward wants to merge 3 commits into
mainfrom
claude/issue-475-20260605-1732
Closed

feat: use official Cloudflare TypeScript API Library#783
andykenward wants to merge 3 commits into
mainfrom
claude/issue-475-20260605-1732

Conversation

@andykenward

Copy link
Copy Markdown
Owner

Closes #475

Replaces hand-rolled fetch + @cloudflare/types with the official cloudflare npm SDK (v4.5.0).

Removes ~580 lines of boilerplate:

  • fetchResult, fetchSuccess, throwFetchError, ParseError (ported from wrangler)
  • getCloudflareApiEndpoint (URL construction now handled by SDK)
  • @cloudflare/types devDependency

Adds:

  • src/common/cloudflare/api/client.ts — thin factory for the SDK client
  • cloudflare@4.5.0 as a bundled dependency

Type improvement: PagesDeployment is now the SDK's Deployment type directly, removing the aliases: string[] | null workaround.

Bundle size needs verification: run pnpm install && pnpm run build and compare dist size.

Generated with Claude Code

github-actions Bot and others added 2 commits June 5, 2026 17:51
Migrate from hand-rolled fetch + @cloudflare/types to the official
`cloudflare` npm SDK. The SDK ships with correctly-typed responses
(including `aliases: string[] | null`, fixing the old workaround),
uses native fetch, and has zero runtime dependencies — so esbuild
tree-shaking keeps the bundle impact minimal.

Removes ~580 lines of custom fetch/error boilerplate:
- fetchResult, fetchSuccess (api/fetch-result.ts)
- throwFetchError, renderError (api/fetch-error.ts)
- ParseError (api/parse-error.ts)
- getCloudflareApiEndpoint (api/endpoints.ts, now handled by SDK)
- @cloudflare/types devDependency

Adds:
- api/client.ts — thin factory for the Cloudflare SDK client
- cloudflare 4.5.0 as a bundled dependency

Error handling in delete.ts now catches Cloudflare.APIError and
inspects the response body for error code 8000009 (already-deleted).
Tests updated: APIError replaces ParseError in error assertions.

Note: run `pnpm install` to update the lockfile, then
`pnpm run all` to verify types, tests, and bundle size.

Co-authored-by: Andy Kenward <andykenward@users.noreply.github.com>
- types.ts: replace @cloudflare/types import with cloudflare SDK
  Deployment type; aliases correctly typed as string[] | null
- get.ts: use SDK client to list deployments via async iteration
- delete.ts: use SDK client; catch Cloudflare.APIError for code 8000009
- endpoints.ts: remove getCloudflareApiEndpoint (SDK handles URLs);
  keep CloudflareApiEndpoint type and getCloudflareLogEndpoint
- endpoints.test.ts: remove getCloudflareApiEndpoint tests
- create.test.ts, status.test.ts: update error assertions to
  Cloudflare.APIError (was ParseError snapshot)

Co-authored-by: Andy Kenward <andykenward@users.noreply.github.com>
@changeset-bot

changeset-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 43ae2d8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@andykenward

Copy link
Copy Markdown
Owner Author

Cloudflare TypeScript API library is too big and has bad TypeScript types.

@andykenward andykenward closed this Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Look into using Cloudflare TypeScript API Library

1 participant